package index;

import java.util.Map;
import java.util.TreeMap;

public class DenseIndex {
	private Map<String,Object> indexedData = new TreeMap<String,Object>();
	
	public void putData(String index,Object data) throws Exception{
		if(indexedData!=null){
			indexedData.put(index, data);
		}else{
			throw new Exception("数据集合异常!");
		}
	}
	
	public Object getData(String index) throws Exception{
		if(indexedData!=null){
			return indexedData.get(index);
		}else{
			throw new Exception("数据集合异常!");
		}
	}
	
	public void displayIndex(){
		for(String dataKey : indexedData.keySet())   {   
		    System.out.println(dataKey);
		}
	}
	
	public static void main(String[] args) throws Exception{
		DenseIndex index = new DenseIndex();
		index.putData("g", "google");
		index.putData("a", "apple");
		index.displayIndex();
		System.out.println(index.getData("a"));
	}
}
